package com.itheima.demo7tcp4;

import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

public class ServerReaderRunnable implements Runnable{
    private Socket socket;
    public ServerReaderRunnable(Socket socket) {
        this.socket = socket;
    }
    @Override
    public void run(){
        try {
//            给当前对应的浏览器管道响应一个网页数据回去
            OutputStream os = socket.getOutputStream();
//            通过字节输出流包装写数据出去给浏览器
//            把字节输出流包装成打印流
            PrintWriter pw = new PrintWriter(os);
            pw.println("HTTP/1.1 200 OK");
            pw.println("Content-Type:text/html;charset=utf-8");
            pw.println();//必须换一行
            pw.println("<html>");
            pw.println("<body>");
            pw.println("<h1>欢迎访问itcast</h1>");
            pw.println("</body>");
            pw.println("</html>");
            pw.flush();
            pw.close();
            socket.close();
        } catch (Exception e) {
            System.out.println("客户"+socket.getPort()+"端断开了连接");
        }
    }
}
